<?php

namespace My\EhrBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use My\EhrBundle\Lib\Pager,
    My\EhrBundle\Entity\Personnel;
use Doctrine\ORM\Query;


class PersonnelController extends Controller
{
   /**
    * @extra:Route("/", name="demo")
    * @extra:Template()
    */
    public function indexAction()
    {
        return array();
    }

    /**
    * @extra:Route("/list",name="_personnel_list")
    * @extra:Template()
    */
    public function listAction()
    {
        $request       = $this->get('request');
        $em            = $this->get('doctrine.orm.entity_manager');
        
        $personnelRepository = $em->getRepository('My\EhrBundle\Entity\Personnel');
        $fieldMaps = $personnelRepository->getFieldsMapOrders();

        $pager = new Pager( $personnelRepository->getAllPersonnelsCount(),
                            $request->query->get('page',1), 
							$request->query->get('max',10) );
		//echo ;
		//exit;
        $results = $personnelRepository->getAllPersonnelsForList( $pager->getOffsetQuery(), 
																  $pager->getPerpage(),
																  $pager->pagination()->getDqlOrderBy($fieldMaps) )
                                       ->getResult(Query::HYDRATE_ARRAY);


        return array( 'personnels' => $results, 'pager' => $pager );
    }
    protected function buildCriteria()
    {
        
        
    }
}